package com.zcx.qshop.conn;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

@HttpInlet(Conn.INLET_JSON_ADDRESS)
public class JsonAddressAsyGet extends QSAsyGet<JsonAddressAsyGet.Info> {

	public String uid;
 
	public JsonAddressAsyGet(String uid, AsyCallBack<Info> asyCallBack) {

		super(asyCallBack);
		
		this.uid = uid;
		
 	} 
	
	@Override
	public Info parser(JSONObject object) {
		
		if(object.optString("message").equals("1")){
			
			Info info = new Info();
			
			JSONArray array = object.optJSONArray("addresslist");
			
			for (int i = 0; i < array.length(); i++) {
				
				Info.Address address = new Info.Address();
				
				JSONObject o = array.optJSONObject(i);
				
				address.aid = o.optString("aid");
				
				address.name = o.optString("name");
				
				address.mobile = o.optString("mobile");

				address.address = o.optString("address");

				address.city = o.optString("city");

				address.citycode = o.optString("citycode");
				
				address.type = o.optString("type");
				
				info.addresses.add(address);
				
			}
			
			return info;
			
		}
		
		return null;
		
	}

	
	public static class Info{
		
		public List<Address> addresses = new ArrayList<Address>();
		
		public static class Address implements Serializable{
			
			public String aid, name, mobile, address, city, citycode, type;
			
		}
		
	}

}
